import requests
from Utils.get_ekp_session import get_session


def get_sap_token():
    session = get_session()
    kl_url = "http://keliu.xincheng.com:8066/#/account"
    session.get(kl_url)
    return session


def get_contract():
    url = "https://oasis-wd.xincheng.com/sap/opu/odata/sap/ZSRE_027N_SRV/$batch?sap-client=800"
    payload = "\r\n--batch_c2a2-7a72-b546\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nGET ZCSRE_I_RECONALIST?sap-client=800&$skip=0&$top=35&$orderby=last_changed%20desc&$filter=zprojid%20eq%20%27E041601%27%20and%20(kstatus%20eq%20%2710%27%20or%20kstatus%20eq%20%2720%27%20or%20kstatus%20eq%20%2730%27%20or%20kstatus%20eq%20%2740%27%20or%20kstatus%20eq%20%2760%27)&$select=objbkey%2crecnnr%2crecntype%2ckcatg%2ckcatgtxt%2cref_version%2cversion%2czprojid%2czprojnm%2czcount%2ckstatus%2cronumber%2ckpage%2cronumberstr%2cact_rtarea%2ckstatustxt%2cbrandname%2cfull_name%2csdate%2cedate%2cname_org1%2cappdat%2ccanchg%2curl%2cmonthup02%2cmonthup01%2clast_changed%2cpstatustxt%2cpstatus%2ccantext%2ccanprint%2ccanedit%2cpobjkey%2csynccpts%2cchg_active_date%2cterminate_date%2cpartner HTTP/1.1\r\nsap-cancel-on-close: true\r\nsap-contextid-accept: header\r\nAccept: application/json\r\nAccept-Language: zh-Hans\r\nDataServiceVersion: 2.0\r\nMaxDataServiceVersion: 2.0\r\nx-csrf-token: dQrhaNVJZjG4JGxK3lmeDQ==\r\n\r\n\r\n--batch_c2a2-7a72-b546\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nGET ZCSRE_I_RECONALIST/$count?sap-client=800&$filter=zprojid%20eq%20%27E041601%27%20and%20(kstatus%20eq%20%2710%27%20or%20kstatus%20eq%20%2720%27%20or%20kstatus%20eq%20%2730%27%20or%20kstatus%20eq%20%2740%27%20or%20kstatus%20eq%20%2760%27) HTTP/1.1\r\nsap-cancel-on-close: true\r\nsap-contextid-accept: header\r\nAccept: text/plain, */*;q=0.5\r\nAccept-Language: zh-Hans\r\nDataServiceVersion: 2.0\r\nMaxDataServiceVersion: 2.0\r\nx-csrf-token: dQrhaNVJZjG4JGxK3lmeDQ==\r\n\r\n\r\n--batch_c2a2-7a72-b546--\r\n"
    # headers = {
    #     'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Microsoft Edge";v="90"',
    #     'MaxDataServiceVersion': '2.0',
    #     'sec-ch-ua-mobile': '?0',
    #     'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.49',
    #     'sap-cancel-on-close': 'true',
    #     'Content-Type': 'multipart/mixed;boundary=batch_c2a2-7a72-b546',
    #     'Accept': 'multipart/mixed',
    #     'sap-contextid-accept': 'header',
    #     'DataServiceVersion': '2.0',
    #     'SAP-PASSPORT': '2A54482A0300E600005A5352455F3032374E40312E302E30202020202020202020202020202020202000005341505F4532455F54415F5573657220202020202020202020202020202020206E74302D2D2D4C6973742D2D736D61727446696C7465724261722D62746E476F5F636C69636B5F3300055A5352455F3032374E40312E302E30202020202020202020202020202020202030354133373838313931444634354532383533354645444138434639333941312020200007A05988E5EF5F43F7B578BC71937DD6FC0000000000000000000000000000000000000000000000E22A54482A',
    #     'Sec-Fetch-Site': 'same-origin',
    #     'Sec-Fetch-Mode': 'cors',
    #     'Sec-Fetch-Dest': 'empty'
    # }
    req = get_sap_token().post(url, data=payload)
    req = get_sap_token().get(url)
    print(req.text)


if __name__ == '__main__':
    get_contract()
